<template>
  <div class="bgbox">
    <div class="logotext">系统登录</div>
    <div class="loginbox">
      <el-form
        ref="formref"
        :model="formData"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="用户名" prop="account" class="account1">
          <el-input v-model="formData.account">
            <i
              slot="prefix"
              class="iconfont icon-account"
              style="color: white"
            ></i>
          </el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            v-model="formData.password"
            auto-complete="off"
            :type="flag ? 'text' : 'password'"
            @keyup.native.enter="submitForm"
          >
            <i
              slot="prefix"
              class="iconfont icon-lock"
              style="color: white"
            ></i>
            <i
              slot="suffix"
              class="iconfont"
              :class="flag ? 'icon-eye-open' : 'icon-eye-close'"
              @click="flag = !flag"
              style="color: white"
            ></i>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('formref')"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapActions } from "vuex";
export default {
  data() {
    return {
      formData: {
        account: "",
        password: "",
      },
      flag: false,
      rules: {
        account: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 3,
            max: 12,
            message: "长度在 3 到 12 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 12,
            message: "长度在 6 到 12 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  // 表单
  methods: {
    ...mapActions("user", ["A_login"]),
    //登录操作
    submitForm() {
      this.$refs.formref.validate(async valid => {
        //判断
        if (valid) {
          //发送请求
          await this.A_login(this.formData);
          this.$router.push("/home");
        } else {
          console.log("验证失败");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.loginbox {
  width: 600px;
  height: 600px;
  text-align: center;
  margin: auto;
  position: absolute;
  top: 406px;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 20px;
}
.bgbox {
  width: 100%;
  height: 100%;
  background: url("../../assets/imgs/bg.jpg") no-repeat;
  background-size: cover;
}
:deep(.el-input__inner) {
  background-color: transparent;
  color: white;
}
:deep(.el-form-item__label) {
  color: white !important;
  font-weight: bold;
}
.logotext {
  width: 200px;
  height: 100px;
  z-index: 666;
  color: white;
  margin: auto;
  position: absolute;
  top: -180px;
  left: 0;
  right: -200px;
  bottom: 0;
  font-size: 30px;
  font-weight: bold;
}
.iconfont {
  font-size: 20px;
}
</style>